//
//  BaseViewController.swift
//  Weibo
//
//  Created by 孙国强 on 2017/6/19.
//  Copyright © 2017年 孙国强. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    var isLogin : Bool = UserAccountViewModel.shareIntance.isLogin

    lazy var visitorView : VisitorView = VisitorView().visitorView()
    
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupNavigationItems()
    }
}

// mark:- 设置UI界面
extension BaseViewController {
    fileprivate func setupVisitorView() {
        view = visitorView
        visitorView.registerBtn.addTarget(self, action: #selector(BaseViewController.registerBtnClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseViewController.loginBtnClick), for: .touchUpInside)
    }
    
    fileprivate func setupNavigationItems() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(BaseViewController.registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(BaseViewController.loginBtnClick))
    }
}

// mark:- 事件监听
extension BaseViewController {
    @objc fileprivate func registerBtnClick() {
        print("registerBtnClick")
    }
    
    @objc fileprivate func loginBtnClick() {
        let OAuthVC = OAuthViewController()
        
        let navVC = UINavigationController(rootViewController: OAuthVC)
        
        present(navVC, animated: true, completion: nil)
    }
}
